# Contributor: Łukasz Jendrysik
# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=monit
pkgver=5.27.0
pkgrel=0
pkgdesc="Managing and monitoring on a UNIX system"
url="https://mmonit.com/monit/"
arch="all"
license="AGPL-3.0-or-later"
makedepends="openssl-dev zlib-dev"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://mmonit.com/monit/dist/monit-$pkgver.tar.gz
	fix-invalid-use-of-vfork.patch
	$pkgname.initd
	"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--without-pam
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
			install -Dm 755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -Dm 644 "$builddir"/monitrc \
		"$pkgdir"/etc/monitrc
	sed -i '/allow @monit/s/^/#/' \
		"$pkgdir"/etc/monitrc
	sed -i '/allow @users readonly/s/^/#/' \
		"$pkgdir"/etc/monitrc

	# monit checks for strict permissions of monitrc at startup
	chmod 600 "$pkgdir"/etc/monitrc
}

sha512sums="34461572ad809917f13672613bd37546ec2b5ebaf5a93a52d669c7c67b102a592ed5e88012feb53c9fe310ea9437a169f8822eac06d7b6f42a1801f710365785  monit-5.27.0.tar.gz
549fda6dc92c2630152a29f5bb94d29a59abb06300e55eb93ed729758d73ed7dceaa2e9f491c9d33419920aef24c0360f865753be28af13a11216129529611ae  fix-invalid-use-of-vfork.patch
cf2b417a73766ff568f1df904f1ccdee1289037994c8ba1743cf1d04cb1ea8945f66d6cb2c9bab868f600a7c7ae57436d1f49cccbe22745b41282034e169ef25  monit.initd"
